package gormprocess

import "gitee.com/lxgow/lxtime"

// index
// 创建时间:下午4:22
// 创建人:lixu

type MData struct {
	NowTime int64
	Ex      int
	Data    interface{}
}

var GLOBALPROCESSEXTENDS = make(map[string]MData)

func Set(name string, data interface{}, times int) {
	GLOBALPROCESSEXTENDS[name] = MData{
		Data:    data,
		NowTime: lxtime.NowUninx(),
		Ex:      times,
	}
	return
}

func Get(name string, result interface{}) (exist bool, err error) {

	if GLOBALPROCESSEXTENDS[name].NowTime < 1 {
		return
	}

	if lxtime.NowUninx() > GLOBALPROCESSEXTENDS[name].NowTime+int64(GLOBALPROCESSEXTENDS[name].Ex) {
		return
	}

	exist = true

	result = GLOBALPROCESSEXTENDS[name].Ex

	return
}
